
import { reqBannerList, reqCategoryList, reqFloorList } from "@/api"

/* home仓库 */
const state = {
  //初始值是根据接口的返回值进行初始化的，服务器返回的是对象还是数组
  categoryList:[],

  //轮播图图片
  bannerList:[],

  //floor数据
  floorList:[]

}

/* 操作state */
const mutations = {
  CATEGORYLIST(state,categoryList){
    state.categoryList = categoryList
  },
  BANNERLIST(state,bannerList){
    state.bannerList = bannerList
  },
  FLOORLIST(state,floorList){
    state.floorList = floorList
  }
}

/* 处理action,可以书写自己的业务逻辑 */
const actions = {
  //通过API里面的接口函数调用，向服务器发请求，获取服务器的数据
  async categoryList({commit}){
    let result = await reqCategoryList();
    if(result.code==200){
      commit("CATEGORYLIST",result.data)
    }
  },
  //获取首页轮播图数据
  async getBannerList({commit}){
    let result = await reqBannerList();
    if(result.code ==200){
      commit('BANNERLIST',result.data)
    }
  },
  //获取floor组件数据[{},{}]
  async getFloorList({commit}){
    let result = await reqFloorList()
    if(result.code == 200){
      commit('FLOORLIST',result.data)
    }
  }
}

//计算属性
const getters = {}
export default {
  state,
  mutations,
  actions,
  getters
}